$(document).ready(function() {
	ajaxPage(1);
	var pageIndex = "";
		
	function ajaxPage(pageIndex) {
	var limit=2;
		$.ajax({
			url : "/SSH_LoginAjaxPage/show.action",
			type : "POST",
			data : "start=" + (pageIndex - 1) *limit + "&limit="+limit,
			dataType : "json",
			success : function(msg) {
				// alert(msg.pageSize);
					msg.result=='0000'?getPage(msg):$("#main").html("sorry lodding error!!!");		
			}
		});
		return false;
	}
	function getPage(msg){
		var str = "";
				for (var i = 0; i < msg.data.length; i++) {
					str += "<div id='xd1_2'><font>" + msg.data[i].EMPNO
							+ "</font><font>" + msg.data[i].ENAME
							+ "</font><font>" + msg.data[i].HIREDATE
							+ "</font></div>";
				}
				$("#xd1_1").html(str);
				var btn="<ul class='turn'>";
				btn+=msg.currentPage==1?"<li><span index='"+msg.prevPage+"'>prev</span></li>": "<li><a index='"+msg.prevPage+"'>prev</a></li>"
				btn+=msg.currentPage==msg.total?"<li><span index='"+msg.nextPage+"'>next</span></li>": "<li><a index='"+msg.nextPage+"'>next</a></li>"
//				var btn="<ul class='turn'><li><a index='"+msg.prevPage+"'>prev</a></li><li><a index='"+msg.nextPage+"'>next</a></li></ul>";
				$("#pageCommentBar #ae1").html(btn+"</ul>");
				$(".turn li a").click(function(){
						ajaxPage($(this).attr("index"));
				});
				
				var num1 = msg.currentPage + 1;
				var num2 = msg.currentPage - 1;
				var pgx="<ul class='pages'>";
				if (num2 > 1) {
					pgx+="<li>...</li>";
				}
				for (var j = 0; j <= 1; j++) {
					if (num2 + j > 0) {
						if((num2+j)==msg.currentPage){
							pgx+="<li><span id='"+(num2 + j)+"'>" + (num2 + j)+ "</span></li>";
						}else{
							pgx+="<li><a id='"+(num2 + j)+"'>" + (num2 + j)+ "</a></li>";
						}
					}
				}
				for (var i = msg.currentPage; i < num1; i++) {
					if (i + 1<= msg.total) {
						if((i + 1)==msg.currentPage){
							pgx+="<li><span id='"+(i + 1)+"'>" + (i + 1)+ "</span></li>";
						}else{
							pgx+="<li><a id='"+ (i + 1)+"'>"+ (i + 1) + "</a></li>";
						}
					}
				}
				if (num1 < msg.total) {
					pgx+="<li>...</li>";
				}			
				$("#pageCommentBar #ae2").html(pgx+"</ul>");
				
				$("#pageCommentBar #ae2 ul a").click(function(){
					var ad=$(this);
					var i=parseInt(ad.attr("id"));
					ajaxPage(i);
				});
				$("#pageCommentBar #ae2 ul span").each(function(index,ts){
					$(this).parent().addClass("current");
				});
	}
});